﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Security.Principal;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Domain_Home;

namespace Service
{
	public partial class DomainAtHomeService : ServiceBase
	{
		private const string Home = "B-BoxtonTerrier";
		private const string Domain = "marnickleau.homenet.org";
		private const string Ip = "192.168.1.9";
		private readonly LocationMonitor _monitor = new LocationMonitor(Home);

		public DomainAtHomeService()
		{
			InitializeComponent();
			_monitor.SsidChanged += (x, y) =>
			{
				if (y.Equals(Home))
				{
					Hosts.Add(Domain, Ip);
				}
				else
				{
					Hosts.Remove(Domain, Ip);
				}
				DnsTools.FlushDll();
			};
		}

		protected override void OnStart(string[] args)
		{
			_monitor.Attach();
		}

		protected override void OnStop()
		{
			_monitor.Detach();
		}
	}
}
